package com.wx.controller;


import com.wx.service.SmbmsUserService;

import lombok.var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {


    @Autowired
    SmbmsUserService smbmsUserService;
    @Autowired
    HttpSession httpSession;

    @Autowired
    RedisTemplate redisTemplate;
    @RequestMapping("/login.do")
    public String login(String userCode,String userPassword ){
        //判断，参数传入
        //var 不是java 语法，
        //插件lombok，自动推导类型
        //最多能支持多少人，使用  100  超时订单管理系统，100使用  1台机器，极限，100使用
        //10台电脑  运行  1000 访问
        //10个tomcat  10session
        //阿里  淘宝
        //阿里云
        var smbmsUserDB = smbmsUserService.getSmbmsUserByUserCode(userCode);
        if(smbmsUserDB!=null){
            if(userPassword.equals(smbmsUserDB.getUserPassword())){
                httpSession.setAttribute("userSession",smbmsUserDB);
                redisTemplate.opsForValue().set("userSession",smbmsUserDB);
                return "frame";
            }
        }

        return "login";
    }

    @RequestMapping("/jsp/logout.do")
    public String logout(){
        httpSession.invalidate();
        redisTemplate.delete("userSession");
        return "login";
    }
}
